package adapter;

import java.util.List;

import com.wonyesoft.wuliu.R;


import javabeen.ReceiveOrderMessageBeen;


import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author 作者 E-mail:
 * @date 创建时间：2015-6-19 上午11:19:36
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class BargainListAdapter extends BaseAdapter {
	private List<ReceiveOrderMessageBeen> bargainlist;

	private Context context;
	private LayoutInflater inflater;

	public BargainListAdapter(Context context,
			List<ReceiveOrderMessageBeen> product_infos) {
		this.context = context;
		this.bargainlist = product_infos;

		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bargainlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return bargainlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 ViewHolder viewHolder;
		// new Thread(new GetViewForRunnable()).start();
		// Log.v("ProductAdapter", "GetView");
		ReceiveOrderMessageBeen data = bargainlist.get(position);
		if (data != null) {
			boolean flag_type = data.getSendertype().equals("1");
			
			if (convertView == null) {
			
				viewHolder = new ViewHolder();

				if (flag_type) {
					convertView = inflater.inflate(
							R.layout.bargain_hz_listviewiteam, null);
					viewHolder.textView1 = (TextView) convertView
							.findViewById(R.id.head_image);

					viewHolder.textView2 = (TextView) convertView
							.findViewById(R.id.message_cent);

				} else {
					convertView = inflater.inflate(
							R.layout.bargain_sj_listviewiteam, null);
					viewHolder.textView1 = (TextView) convertView
							.findViewById(R.id.head_image);

					viewHolder.textView2 = (TextView) convertView
							.findViewById(R.id.message_cent);

				}
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) convertView.getTag();
			
			}
			if (flag_type) {
				viewHolder.textView1.setText("货主");
				if (data.getType().equals("1")) {
					viewHolder.textView2.setText("点击播放声音");
				}else {
					viewHolder.textView2.setText(data.getContent());
				}
				
			} else {
				viewHolder.textView1.setText("司机");
				if (data.getType().equals("1")) {
					viewHolder.textView2.setText("点击播放声音");
				}else {
					viewHolder.textView2.setText(data.getContent());
				}
			}
		}
		return convertView;
	}

	class ViewHolder {
		TextView textView1;
		TextView textView2;

	}

}
